package cn.edu.nju.software.android.activity;

import cn.edu.nju.software.android.model.Status;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.annotation.SuppressLint;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;

@SuppressLint("HandlerLeak")
public class RetweetActivity extends Activity {
	private long status_id;
	private Handler handler = new Handler(){
		@Override
		public void handleMessage(Message msg) {
			Toast.makeText(RetweetActivity.this, "发布成功", Toast.LENGTH_SHORT).show();
		}
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_retweet);
		Intent i = getIntent();
		status_id = i.getLongExtra("status_id", 0);
		ActionBar actionBar = getActionBar();
		actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.retweet, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch(item.getItemId()){
		case android.R.id.home:
			finish();
			break;
		case R.id.send:
			EditText editText = (EditText)findViewById(R.id.weibo_content);
			String statusContent = editText.getText().toString();
			if(statusContent.length() <= 0){
				Toast.makeText(this, "请输入内容", Toast.LENGTH_SHORT).show();
			}else{
				String lat = "0.0";
				String lon = "0.0";
				Status status = new Status(statusContent, lat, lon);
				status.repost(status_id, handler);
			}
			finish();
			break;
		default:
			return true;
		}
		return false;
	}

}
